package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.BaseCheckStoreDetailMapper;
import com.kaili.basic.mapper.BaseCheckStoreMapper;
import com.kaili.basic.pojo.dto.BaseCheckStoreAddDTO;
import com.kaili.basic.pojo.dto.BaseCheckStoreDetailAddDTO;
import com.kaili.basic.pojo.entity.BaseCheckStoreDetailEntity;
import com.kaili.basic.pojo.entity.BaseCheckStoreEntity;
import com.kaili.basic.pojo.entity.BaseStoreStockEntity;
import com.kaili.basic.service.BaseCheckStoreDetailService;
import com.kaili.basic.service.BaseCheckStoreService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BaseCheckStoreDetailServiceImpl extends ServiceImpl<BaseCheckStoreDetailMapper, BaseCheckStoreDetailEntity> implements BaseCheckStoreDetailService {


    @Override
    public void insertBath(List<BaseStoreStockEntity> list, BaseCheckStoreDetailAddDTO addDTO) {
        List<BaseCheckStoreDetailEntity> detailList=new ArrayList<>();
        for (BaseStoreStockEntity detail:list) {
            if(detail.getCurrAmount()<=0){
                continue;
            }
            BaseCheckStoreDetailEntity entity=new BaseCheckStoreDetailEntity();
            BeanUtils.copyProperties(detail,entity);
            entity.setId(null);
            entity.setOrderNo(addDTO.getOrderNo());
            entity.setCreateTime(new Date());
            entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
            entity.setPaperAmount(detail.getCurrAmount());
            entity.setPaperTrays(detail.getCurrTrays());
            entity.setPaperVolume(detail.getCurrVo());
            entity.setPaperWeight(detail.getCurrWeight());
            detailList.add(entity);
        }
        this.insertBatch(detailList);
    }
}
